#!/bin/bash
#
# startup.sh -- lab specific startup script,
#

TOP_DIR=$(cd $(dirname $0) && pwd)/

[ ! -d /proc ] && mount -t proc none /proc

# modules loading
grep -qi intel /proc/cpuinfo
if [ $? -eq 0 ]; then
  kvm_dri=kvm-intel
else
  kvm_dri=kvm-amd
fi

modules="loop minix nfsd 9pnet_virtio kvm $kvm_dri"

for m in $modules
do
  modprobe -d /m -n $m > /dev/null 2>&1
  [ $? -ne 0 ] && continue

  lsmod | grep -q $m
  [ $? -ne 0 ] && modprobe -d /m $m >/dev/null 2>&1

  # tell user enable cpu virtualization in bios if not disabled
  if [ $? -ne 0 ]; then
    if [ "$m" = "kvm-intel" -o "$m" = "kvm-amd" ]; then
      echo "LOG: Please turn on cpu virtualization in bios if want use kvm speedup"
    fi
  fi
done

# Insert missing kernel modules

$TOP_DIR/insmod.sh

# Enable network bridge support

$TOP_DIR/enable_net_bridge.sh
